package com.ruoyi.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.pms.entity.YytAcupunctureType;
import com.ruoyi.common.pms.service.YytAcupunctureTypeService;
import com.ruoyi.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ruoyi.common.pms.entity.YytAcupunctureInfo;
import com.ruoyi.common.pms.service.YytAcupunctureInfoService;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
    *  前端控制器
    * </p>
*
* @author MrPing
* @since 2022-03-22
*/
@RestController
@RequestMapping("/acupunctureInfo")
public class YytAcupunctureInfoController {

    @Autowired
    private YytAcupunctureInfoService yytAcupunctureInfoService;

    @Autowired
    private YytAcupunctureTypeService yytAcupunctureTypeService;


    /**
     * 根据穴位 id 和 名称  获取详情
     * @return
     */
    @GetMapping("/getAcupointInfo")
    public ResponseResult getAcupointInfo(@RequestParam("id") Integer id, @RequestParam("name") String name){
        QueryWrapper<YytAcupunctureInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("father_three_id", id).eq("father_name", name).orderByAsc("id");

        return ResponseResult.success(yytAcupunctureInfoService.list(wrapper));
    }

    /**
     * 点击所属经络
     * @return
     */
    @GetMapping("/getFatherInfo")
    public ResponseResult getFatherInfo(@RequestParam("id") String id, @RequestParam("name") String name){
        QueryWrapper<YytAcupunctureType> typeQueryWrapper = new QueryWrapper<>();
        typeQueryWrapper.eq("three_id", id);
        YytAcupunctureType byId = yytAcupunctureTypeService.getOne(typeQueryWrapper);

        QueryWrapper<YytAcupunctureInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("father_three_id", byId.getFather()).eq("father_name",name).orderByAsc("id");

        return ResponseResult.success(yytAcupunctureInfoService.list(wrapper));
    }

}
